package com.rivulet.doj_backend.controller;

import com.rivulet.doj_backend.service.MessageService;
import com.rivulet.doj_backend.tools.ResultFul;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

@CrossOrigin(origins = {"http://localhost:8080", "null"})
@RestController
@RequestMapping(value = "/doj")
public class MessageController {
    @Autowired
    MessageService messageService;

    @RequestMapping(
            value = {"/message/class/{class_id}/user/{user_id}"},
            method = {RequestMethod.POST}
    )
    public ResultFul addMessage(@PathVariable Integer class_id, @PathVariable Integer user_id, @RequestBody HashMap<String,String> map) {
        Integer message_id = Integer.valueOf(map.get("message_id"));
        Integer message_range = Integer.valueOf(map.get("message_range"));
        String message_content = map.get("message_content");
        return this.messageService.addMessage(message_id, message_range, message_content,user_id,class_id);
    }

    @RequestMapping(value = ("/class/{class_id}/join/user/{user_id}"),method = RequestMethod.POST)
    public ResultFul setUserJoinClass(@PathVariable Integer class_id,@PathVariable Integer user_id) {
        return messageService.setUserJoinClass(user_id,class_id);
    }

    @RequestMapping(value = ("/user/{user_id}/competition/{competition_id}"),method = RequestMethod.POST)
    public ResultFul competitionMessage(@PathVariable Integer user_id,@PathVariable Integer competition_id) {
        return messageService.competitionMessage(user_id,competition_id);
    }

    @RequestMapping(value = {"/message/all/{user_id}"}, method = {RequestMethod.POST})
    public ResultFul addAllMessage(@PathVariable Integer user_id,@RequestBody HashMap<String,String> map) {
        Integer message_id = Integer.valueOf(map.get("message_id"));
        Integer message_range=Integer.valueOf(map.get("message_range"));
        String message_content = map.get("message_content");
        return this.messageService.addAllMessage(message_id, message_range, message_content, user_id);
    }
}
